<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015-8-25
 * Time: 10:13
 */
namespace console\components\task;

use common\components\services\message\JpushMessage;
use common\components\services\message\MailMessage;
use common\components\services\message\SmsMessage;
use common\components\services\message\SysMessage;
use common\components\services\message\WechatMessage;
use common\models\datas\MessageLog;
use yii\base\BaseObject;
use yii\helpers\ArrayHelper;
use common\components\services\message\Message;
use yii\helpers\Json;

class TaskMessageManage extends BaseObject
{
    public $data;

    function init()
    {
        parent::init();
        if (ArrayHelper::keyExists('messagelog_id', $this->data['data'], false) && ArrayHelper::keyExists('message_type', $this->data['data'], false)) {
            switch ($this->data['data']['message_type']) {
                case Message::SYS_MESSAGE:
                    $mailObject = \Yii::createObject(['class' => SysMessage::className()]);
                    $mailObject->send($this->data['data']['messagelog_id'],$this->data['site_id']);
                    break;
                case Message::SMS_MESSAGE:
                    $mailObject = \Yii::createObject(['class' => SmsMessage::className()]);
                    /*\Yii::error('sms message messgelog_id:');
                    \Yii::error($this->data['data']['messagelog_id']);
                    \Yii::error('sms message messgelog data:');
                    \Yii::error($this->data);*/
                    $mailObject->send($this->data['data']['messagelog_id'],$this->data['site_id']);
                    break;
                case Message::MAIL_MESSAGE:
                    $mailObject = \Yii::createObject(['class' => MailMessage::className()]);
                    $mailObject->send($this->data['data']['messagelog_id'],$this->data['site_id']);
                    break;
                case Message::WECHAT_MESSAGE:
                    $mailObject = \Yii::createObject(['class' => WechatMessage::className()]);
                    $mailObject->send($this->data['data']['messagelog_id'],$this->data['site_id']);
                    break;
                case Message::JPUSH_MESSAGE:
                    $mailObject = \Yii::createObject(['class' => JpushMessage::className()]);
                    $mailObject->send($this->data['data']['messagelog_id'],$this->data['site_id']);
                    break;
            }
        }

    }
}